﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>
  

  <xsl:template match="server">
    <xsl:param name="application" />
    <xsl:param name="server" />

    <!-- Switch to the manifest template-->
    <xsl:call-template name="SwitchToManifestTemplate">
      <xsl:with-param name="application" select="$application" />
      <xsl:with-param name="server" select="$server" />
    </xsl:call-template>

    <!-- copy server Attribute to the new current server node that we are creating -->
    <xsl:apply-templates select="@*" mode="copyAttribute" />

    <!-- Browse folders to create Folder attribute -->
    <xsl:apply-templates select="./folders">
      <xsl:with-param name="application" select="$application" />
      <xsl:with-param name="server" select="$server" />
    </xsl:apply-templates>

  </xsl:template>

  <xsl:template match="server" mode="deploymentV2.0">
    <xsl:param name="application" />

    <xsl:variable name="templateName" select="@template" />
    <xsl:variable name="elementName" select="name()" />

    <xsl:if test="$templateName != ''">
      <xsl:apply-templates select="//templates/template[@type=$elementName and @name= $templateName]/*" mode="deploymentV2.0">
        <xsl:with-param name="application" select="$application" />
      </xsl:apply-templates>
    </xsl:if>
        
    <xsl:apply-templates select="./*" mode="deploymentV2.0">
      <xsl:with-param name="current" select="./*" />
    </xsl:apply-templates>


  </xsl:template>

 

  <!-- Begin : Security binding  -->
  <xsl:template match="security/add" mode="deploymentV2.0">
    <xsl:variable name="mappingSecurity" select="./@name" />
    <xsl:apply-templates select="//usersAndGroups/usersAndGroup[@name=$mappingSecurity]/add[@environment=$EnvironmentTarget]" mode="deploymentV2.0" />
    <xsl:apply-templates select="./@*" mode="copyAttribute" />
  </xsl:template>

  <xsl:template match="usersAndGroup/add" mode="deploymentV2.0">
    <xsl:apply-templates select="./@*" mode="copyAttribute" />
  </xsl:template>
  <!-- End : Security Binding-->


  <!-- Begin tools function -->

  



  <!-- End tools function -->


  <!-- Begin OLd template to apply relative attribute. It's working but must describe each element-->


  <!-- Good for folders
  <xsl:template match="server" mode="ApplyRelativeAttributeValue">
    <xsl:param name="relativeValue" />
    <xsl:param name="application" />
    <xsl:param name="middlewareTarget" />

    <xsl:variable name="templateName" select="@template" />
    <xsl:variable name="elementName" select="name()" />

    <xsl:if test="$templateName != ''">
      <xsl:apply-templates select="//templates/template[@type=$elementName and @name= $templateName]/*" mode="ApplyRelativeAttributeValue">
        <xsl:with-param name="relativeValue" select="$relativeValue" />
        <xsl:with-param name="application" select="$application" />
        <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
      </xsl:apply-templates>
    </xsl:if>


    <xsl:choose>
      <xsl:when test="name()=$relativeValue/@parent">
        -->
  <!-- We are on the parent node for the related attribute so we can search the targetType -->
  <!--
        <xsl:apply-templates select="./*/*[name()=$relativeValue/@targetedType]" mode="ApplyRelativeAttributeValue">
          <xsl:with-param name="relativeValue" select="$relativeValue" />
          <xsl:with-param name="application" select="$application" />
          <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
        </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
        -->
  <!-- Browse parent type to find relative attribute -->
  <!--
        <xsl:apply-templates select="./*/*[name()=$relativeValue/@parent]" mode="ApplyRelativeAttributeValue">
          <xsl:with-param name="relativeValue" select="$relativeValue" />
          <xsl:with-param name="application" select="$application" />
          <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
        </xsl:apply-templates>
      </xsl:otherwise>
    </xsl:choose>


  </xsl:template>


  <xsl:template match="middleware" mode="ApplyRelativeAttributeValue">
    <xsl:param name="relativeValue" />
    <xsl:param name="application" />
    <xsl:param name="middlewareTarget" />

    <xsl:variable name="templateName" select="@template" />
    <xsl:variable name="elementName" select="name()" />

    <xsl:if test="$templateName != ''">
      <xsl:apply-templates select="//templates/template[@type=$elementName and @name= $templateName]/*" mode="ApplyRelativeAttributeValue">
        <xsl:with-param name="relativeValue" select="$relativeValue" />
        <xsl:with-param name="application" select="$application" />
        <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
      </xsl:apply-templates>
    </xsl:if>

    <xsl:apply-templates select="./executionContainer[@name=$middlewareTarget]" mode="ApplyRelativeAttributeValue">
      <xsl:with-param name="relativeValue" select="$relativeValue" />
      <xsl:with-param name="application" select="$application" />
      <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
    </xsl:apply-templates>

  </xsl:template>

  <xsl:template match="executionContainer" mode="ApplyRelativeAttributeValue">
    <xsl:param name="relativeValue" />
    <xsl:param name="application" />
    <xsl:param name="middlewareTarget" />

    <xsl:variable name="templateName" select="@template" />
    <xsl:variable name="elementName" select="name()" />

    <xsl:if test="$templateName != ''">
      <xsl:apply-templates select="//templates/template[@type=$elementName and @name= $templateName]/*" mode="ApplyRelativeAttributeValue">
        <xsl:with-param name="relativeValue" select="$relativeValue" />
        <xsl:with-param name="application" select="$application" />
        <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
      </xsl:apply-templates>
    </xsl:if>

    -->
  <!-- Browse folders to create Folder attribute -->
  <!--
    <xsl:apply-templates select="./*/*[name()=$relativeValue/@targetedType]" mode="ApplyRelativeAttributeValue">
      <xsl:with-param name="relativeValue" select="$relativeValue" />
      <xsl:with-param name="application" select="$application" />
      <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
    </xsl:apply-templates>


  </xsl:template>

  <xsl:template match="folder" mode="ApplyRelativeAttributeValue">
    <xsl:param name="relativeValue" />
    <xsl:param name="application" />
    <xsl:param name="middlewareTarget" />

    <xsl:variable name="templateName" select="@template" />
    <xsl:variable name="elementName" select="name()" />

    <xsl:if test="$templateName != ''">
      <xsl:apply-templates select="//templates/template[@type=$elementName and @name= $templateName]/*" mode="ApplyRelativeAttributeValue">
        <xsl:with-param name="relativeValue" select="$relativeValue" />
        <xsl:with-param name="application" select="$application" />
        <xsl:with-param name="middlewareTarget" select="$middlewareTarget" />
      </xsl:apply-templates>
    </xsl:if>


    <xsl:if test="@name and @name=$relativeValue/@targetedName">
      <xsl:apply-templates select="." mode="GetRelativeValue">
        <xsl:with-param name="relativeAttribute" select="$relativeValue" />
      </xsl:apply-templates>
    </xsl:if>

  </xsl:template>-->


  <!-- End OLd template to apply relative attribute. It's working but must describe each element-->





</xsl:stylesheet>
